***Replication code for the article: Closing the gender gap in internal political efficacy? Gender Roles and the Masculine Ethos of Politics in Spain***
***Authors: Fraile, Marta and Marinova, Dani. October 2023**

********************************************************************************
********Analysis of observational data: survey fielded in December of 2020********
********************************************************************************

use Study 1_Survey.dta, clear

***Dependent variable IPE index
*Index of ipe: 
gen newipe=item1+item2+item4
tab newipe
recode newipe 12=11
tab newipe
sum newipe

******creating an index of all six agentic traits
alpha P9_1 P9_3 P9_5 P9_7 P9_9 P9_11
corr P9_1 P9_3 P9_5 P9_7 P9_9 P9_11
factor P9_1 P9_3 P9_5 P9_7 P9_9 P9_11

gen agenticindex=P9_1+P9_3+P9_5+P9_7+P9_9+P9_11 
tab agenticindex
recode agenticindex 0/11=0 12/13=1 14/15=2 16/17=3 18/19=4 20/21=5 22/23=6 24=7 25=8 26=9 27=10 28=11 ///
29=12 30=13 31=14 32=15 33=16 34=17 35=18 36=19 37=20 38=21 39=22 40=23 41=24 42=25 43=26 44=27 45=28 ///
46=29 47=30 48/49=31 50=32 51/60=33
tab agenticindex

mean agenticindex, over (female) 
reg agenticindex female


***creating an index of all six communal traits
alpha P9_2 P9_4 P9_6 P9_8 P9_10 P9_12 
*alpha=0,702**
corr P9_2 P9_4 P9_6 P9_8 P9_10 P9_12 
factor P9_2 P9_4 P9_6 P9_8 P9_10 P9_12 


gen communality=P9_2+P9_4+P9_6+P9_8+P9_10+P9_12 
tab communality
recode communality 8/26=0 27/29=1 30=2 31=3 32=4 33=5 34=6 35=7 36=8 37=9 38=10 39=11 40=12 41=13 42=14 ///
43=15 44=16 45=17 46=18 47=19 48=20 49=21 50=22 51=23 52=24 53=25 54=26 55=27 56=28 57=29 58=30 59=31 60=32
tab communality


mean communality, over (female) 
reg communality female

**black & white
set scheme s1mono
gen sexagentic=female*agenticindex
gen sexcommunal=female*communality 

**Table 1-Internal political efficacy: OLS estimates 
reg newipe female education age kids
est store ipe1
reg newipe female agenticindex communality education age kids
est store ipe2 
reg newipe female agenticindex sexagentic communality education age kids  
est store ipe3
reg newipe female sexcommunal communality education age kids  
est store ipe4
estout ipe1 ipe2 ipe3 ipe4, cells(b(star fmt(2)) se)  stats(N r2) 


*** Figure 3. Predicted internal political efficacy for women and men by Agentic Index 

reg newipe i.female##c.agenticindex education age kids 
margins female, at(agenticindex=(0(4)32))
marginsplot, scheme (s2mono) ysc(r(0, 7)) ylabel(0 1 2 3 4 5 6 7) xtitle("Agentic Index") ytitle("Predicted Internal Political Efficacy") title(" ") 


*** Replication with marhis 
reg newipe c.agenticindex##i.female education age kids 
marhis agenticindex, cate(female) 



*** Table A1. Appendix
sum newipe female agenticindex communality education age kids

*******************************************************************************
************************** Code to generate Figure 2 **************************
*******************************************************************************

gen full=1 if !missing(newipe, female, education, age, kids, agenticindex)

keep if full==1
keep newipe female education age kids agenticindex


twoway (histogram newipe if female==1, percent lcolor(gs13) fcolor(gs13) discrete yline(10, lcolor(gs13))) ///
       (histogram newipe if female==0, percent fcolor(none) lcolor(gs4) discrete yline(5, lcolor(gs13)) yline(15, lcolor(gs13)) yline(20, lcolor(gs13)) ), ///
	   legend(order(1 "Women" 2 "Men" )) xtitle("Internal political efficacy") 
	   
	   
	   
	   

*******************************************************************************
************** Summary statistics to replicate Figures 1 and 4 ****************
*******************************************************************************
 
use Study 1_Survey.dta, clear

* Summary statistics reported in the article
* Used to generate Figure 1
foreach var of varlist P9_*{
	tab `var'
}

***gender differences in traits***
foreach var of varlist P9_*{
	mean `var', over (female) 
}
* save to P9tval_CI_tograph.dta


***TRAITS MORE TYPICAL OF MEN AND WOMEN
foreach var of varlist P10_*{
	tab `var' 
}

foreach var of varlist P10_*{
	tab `var' female, col
}
* save to P10_tval_CI_tograph.dta

*** Words associated to the political world
*** Used to generate Figure 4
tab1 P17_*

*** Dummies with values very much 
tab1 power agree promo solve competi servi

*** Words associated to politicians' motivations
recode  P18_* (98=.)
tab1 P18_*
* save to Fig4_means.dta
	   
	   
*******************************************************************************
************************** Code to generate Figure 1 **************************
*******************************************************************************

*** Top panel of Figure 1
use P9tval_CI_tograph.dta, clear
set scheme s1mono

twoway ///
(rcap low95 high95 row, horizontal) /// code for 95% CI
(scatter row tval, mcolor(black)) /// dot 
, legend(row(1) order(2 "Differences between men and women") pos(6) size(small)) /// legend at 6 o'clock position
ylabel(1 "Self-confident" 3 "Ambitious" 5 "Risk-seeking"  7 "Competitive" ///
9 "Conflictive" 11 "Strong personality" 13 "Empathetic" 15 "Affective" ///
17 "Compassionate" 19 "Kind" 21 "Attentive" 23 "Warm", angle(0) noticks) ///
/// note that the labels are 1.5, 4.5, etc so they are between rows 1&2, 4&5, etc.
/// also note that there is a space in between different rows by leaving out rows 3, 6, 9, and 12 
/// no 1.6 label
title("A. Self-placement") ///
xtitle("") /// 
ytitle("") /// 
yscale(reverse) /// y axis is flipped
xline(0, lpattern(solid) lcolor(gs10)) ///
aspect(.5)

*** Bottom panel of Figure 1
use P10_tval_CI_tograph.dta, clear
twoway ///
(rcap low95 high95 row, horizontal) /// code for 95% CI
(scatter row tval, mcolor(black)) /// dot 
, legend(row(1) order(2 "Differences ascribed to men and women") pos(6) size(small)) /// legend at 6 o'clock position
ylabel(1 "Self-confident" 3 "Ambitious" 5 "Risk-seeking" 7 "Competitive" 9 "Conflictive"  ///
11 "Strong personality" 13 "Empathetic" 15 "Affective" 17 "Compassionate" 19 "Kind" 21 "Attentive" ///
23 "Warm", angle(0) noticks) ///
/// note that the labels are 1.5, 4.5, etc so they are between rows 1&2, 4&5, etc.
/// also note that there is a space in between different rows by leaving out rows 3, 6, 9, and 12 
/// no 1.6 label
title("B. Women and Men in Society") ///
xtitle("") xlabel(-1(.5)1.5) /// 
ytitle("") /// 
yscale(reverse) /// y axis is flipped
xline(0, lpattern(solid) lcolor(gs10)) ///
aspect(.5)


*******************************************************************************
************************** Code to generate Figure 4 **************************
*******************************************************************************

use Fig4_means.dta, clear

graph hbar (mean) politics, over(var1, sort(1) descending) ytitle("") title("A. Politics") yscale(r(0 100)) ylabel(0(20)100) nofill

graph hbar (mean) politicians, over(var3, sort(1) descending) ytitle("Percent 'Very Much'") title("B. Politicians") yscale(r(0 100)) ylabel(0(20)100) nofill


********************************************************************************
***Analysis of experimental data: survey experiment fielded in June of 2020***
********************************************************************************

use  Study 2_Experiment.dta
 
**black & white
set scheme s1mono

*rule to select participants
recode TIEMPO_P18 1104/10816=.
tab TIEMPO_P18
gen select=0
recode select 0=1 if correct==1&(TIEMPO_P18>40 | TIEMPO_P18==.)
tab select
tab select GRUPO, col

gen grupo=GRUPO
recode grupo 3=0
tab grupo
label def g 0 "control" 1 "power" 2 "service"
label val grupo g 
tab grupo

***working versus the rest
gen working=0
recode working 0=1 if P5_1==1
tab working


*** Internal validity of the experiment***
tab1 P19 P20 P21
tab1 P23*

***Manipulation checks
tab P19 grupo, col
tab P20 grupo, col
tab P21 grupo, col
tab correct grupo, col

***effectiveness of the treatment
reg P23_1 grupo
reg P23_2 grupo
reg P23_1 grupo

*--> NEW IPE ITEM: ipe4
*IPE4: composed of items P22_2, P22_3 and P22_6
gen ipe4 = P22_6 + P22_2 + P22_3
sum ipe4
tab ipe4
label define g 0 "Control" 1 "Agentic" 2 "Communal", replace
label define sex 0 "Men", modify
label define sex 1 "Women", modify
label variable women " "


*Main model
reg ipe4 i.women##i.grupo if correct!=0 & (TIEMPO_P18>40 | TIEMPO_P18==.)
margins grupo#women
*** Replication Figure 5A
marginsplot, recast(scatter) scheme (s1mono) ytitle("") title("Gender differences in Political Efficacy by Treatment")

*Replication with more stringent 83.5 confidence interval level
reg ipe4 i.women##i.grupo if correct!=0 & (TIEMPO_P18>40 | TIEMPO_P18==.)
margins grupo#women
*** Replication Figure 5B
marginsplot, recast(scatter) scheme (s1mono) level(83.5) ytitle("") title("Gender differences in Political Efficacy by Treatment with 83.4% CIs")

*Replication with controls for age, education level and working status
reg ipe4 i.women##i.grupo age education working if correct!=0 & (TIEMPO_P18>40 | TIEMPO_P18==.)
margins grupo#women
marginsplot, recast(scatter) scheme (s1mono)

***TABLE A-4
reg ipe4 i.women##i.grupo if correct!=0 & (TIEMPO_P18>40 | TIEMPO_P18==.)
est store ipe1
reg ipe4 i.women##i.grupo age education working if correct!=0 & (TIEMPO_P18>40 | TIEMPO_P18==.)
est store ipe2

*** Table A3. in the Appendix
estout ipe1 ipe2, cells(b(star fmt(2)) se)  stats(N r2) 


*Table with summary statistics for variables in main and ancilliary models
* Tabñe A2- om the Appendix
sum ipe4 women age education working grupo correct

